package cn.star.jots.filmSort.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.filmSort.pojo.dto.FilmSortSaveParam;
import cn.star.jots.filmSort.pojo.vo.FilmSortVO;
import cn.star.jots.filmSort.service.FilmSortService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/filmSort")
@Api(tags = "用户端首页电影管理")
@Slf4j
public class FilmSortController {

    @Autowired
    FilmSortService filmSortService;

    @GetMapping("/select/{sort}")
    @ApiOperation(value = "查询首页电影信息")
    private JsonResult select(@PathVariable Integer sort) {
        log.info("查询首页电影信息:sort={}", sort);
        List<FilmSortVO> list = filmSortService.selectFirst(sort);
        return JsonResult.ok(list);
    }

    @GetMapping("/select/notIn/{sort}")
    @ApiOperation(value = "查询首页电影除了sort为1的其他信息")
    private JsonResult selectNotIn(@PathVariable Integer sort) {
        log.info("查询首页电影除了sort为1的其他信息:sort={}", sort);
        List<FilmSortVO> list = filmSortService.selectNotIn(sort);
        return JsonResult.ok(list);
    }

    @GetMapping("/selectAll")
    @ApiOperation(value = "查询首页电影信息")
    private JsonResult selectAll() {
        log.info("查询首页电影信息");
        List<FilmSortVO> list = filmSortService.selectAll();
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存首页电影信息")
    private JsonResult save(FilmSortSaveParam filmSortSaveParam) {
        log.info("保存首页电影信息:filmSortSaveParam={}", filmSortSaveParam);
        filmSortService.save(filmSortSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("/selectById/{id}")
    @ApiOperation(value = "根据id查询首页电影信息")
    private JsonResult selectById(@PathVariable Long id) {
        log.info("根据id查询首页电影信息:id={}", id);
        List<FilmSortVO> list = filmSortService.selectById(id);
        return JsonResult.ok(list);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除首页电影信息")
    private JsonResult delete(@PathVariable Long id) {
        log.info("根据id删除首页电影信息:id={}", id);
        filmSortService.delete(id);
        return JsonResult.ok();
    }
}
